#pragma once
#ifndef __GAMEOBJECT_H__
#define __GAMEOBJECT_H__

#include "Utility.h"

#include "../util/D3DCommon.h"
#include "../util/PreDeclare.h"

namespace WindGE
{
	class WIND_CORE_API GameObject : public std::enable_shared_from_this<GameObject>
	{
	public:
		GameObject();
		GameObject(const std::string& name);
		~GameObject();

		inline const XMFLOAT3& translate()	const	{ return position_; }
		inline const XMFLOAT4& rotation()	const	{ return rotation_; }
		inline const XMFLOAT3& scaling()	const	{ return scaling_;  }

		inline void set_translate(const XMFLOAT3& pos)	{ position_ = pos;  }
		inline void set_rotation(const XMFLOAT4& rot)	{ rotation_ = rot;  }
		inline void set_rotation(const XMFLOAT3& eulerAngle);
		inline void set_scaling(const XMFLOAT3& scale)	{ scaling_ = scale; }

		const XMFLOAT3& euler_angle() const;

		XMMATRIX matrix() const;
		const XMFLOAT4X4& matrix_data() const;

		inline guid_ptr id() const			{ return id_;	}
		inline void  set_id(guid_ptr id)	{ id_ = id;		}

	protected:
		GameObjectPtr get_child(unsigned int i) const;
		inline GameObjectPtr_Weak get_parent()  const { return parent_; }

	protected:
		std::vector<GameObjectPtr>	children_;
		GameObjectPtr_Weak			parent_;

	protected:
		XMFLOAT3	position_;
		XMFLOAT4	rotation_;
		XMFLOAT3	scaling_;
	
	protected:
		guid_ptr	id_;
	};

	inline void GameObject::set_rotation(const XMFLOAT3& eulerAngle)
	{
		XMVECTOR R = XMLoadFloat3(&eulerAngle) / 180 * Pi;
		XMVECTOR RQuad = XMQuaternionRotationRollPitchYawFromVector(R);
		XMStoreFloat4(&rotation_, RQuad);
	}

}//end namespace WindGE

#endif // !__GAMEOBJECT_H__
